package com.sense.kukoo.biz_explore.adapter.provider

import android.view.View
import android.widget.TextView
import com.sense.kukoo.biz_explore.adapter.SearchAdapter
import com.sense.kukoo.common.R
import com.sense.kukoo.common.repo.bean.SearchBean
import com.sense.kukoo.common.wiget.adapter.provider.MultiItemProvider
import com.sense.kukoo.common.wiget.adapter.viewholder.BaseViewHolder

class SearchRecommendItemProvider(val listener: SearchAdapter.SearchEventListener) :
    MultiItemProvider<SearchBean>() {

    override fun getItemType(): Int = SearchBean.TYPE_RECOMMEND

    override fun getItemLayoutId(): Int = R.layout.common_search_recommend

    override fun onBindViewHolder(viewHolder: BaseViewHolder, item: SearchBean) {
        val recommend = item.recommend
        val listOf = arrayListOf(
                viewHolder.getView(R.id.tv_recommend_1) as TextView,
                viewHolder.getView(R.id.tv_recommend_2) as TextView,
                viewHolder.getView(R.id.tv_recommend_3) as TextView,
                viewHolder.getView(R.id.tv_recommend_4) as TextView,
                viewHolder.getView(R.id.tv_recommend_5) as TextView,
                viewHolder.getView(R.id.tv_recommend_6) as TextView,
        )
        for ((index:Int, tv :TextView) in listOf.withIndex()) {
            if(index < recommend.size){
                tv.visibility = View.VISIBLE
                val text = recommend.get(index)
                tv.setText(text)
                tv.setOnClickListener {
                    listener.onRecommendItemClick(item, index, text)
                }
            }else{
                tv.visibility = View.GONE
            }
        }
    }
}